package com.gonsin.gview.model.dynamic.data;

import com.gonsin.gview.annotations.impl.EmptyListDataPicker;
import com.gonsin.gview.annotations.interfaces.IListDataPicker;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;

@Data
public class DynamicTreeData {

    /**
     * 直接输入sql语句查询数据（如果查询到多个，则会返回第一个）
     */
    private String fromSql = "";
    public static DynamicTreeDataBuilder fromSql(String fromSql){
        DynamicTreeDataBuilder data = new DynamicTreeDataBuilder();
        data.fromSql = fromSql;
        return data;
    }

    /**
     * 通过dataPicker写java语句查询数据（此方法最为灵活）
     */
    private IListDataPicker fromListDataPicker;
    public static DynamicTreeDataBuilder fromListDataPicker(IListDataPicker fromListDataPicker){
        DynamicTreeDataBuilder data = new DynamicTreeDataBuilder();
        data.fromListDataPicker = fromListDataPicker;
        return data;
    }

    /**
     * 通过dataPicker写java语句查询数据（此方法最为灵活）
     */
    private String fromListDataPickerClassName = "";
    public static DynamicTreeDataBuilder fromListDataPickerClassName(String fromListDataPickerClassName){
        DynamicTreeDataBuilder data = new DynamicTreeDataBuilder();
        data.fromListDataPickerClassName = fromListDataPickerClassName;
        return data;
    }

    /**
     * 通过静态json返回，适合静态数据
     */
    private String fromJson = "";
    public static DynamicTreeDataBuilder fromJson(String fromJson){
        DynamicTreeDataBuilder data = new DynamicTreeDataBuilder();
        data.fromJson = fromJson;
        return data;
    }

    /**
     * 通过枚举名称获取
     */
    private String fromEnums = "";
    public static DynamicTreeData fromEnums(String fromEnums){
        DynamicTreeData data = new DynamicTreeData();
        data.fromEnums = fromEnums;
        return data;
    }

    /**
     * 通过@GDataSource获取数据
     */
    private String fromDataSource = "";
    public static DynamicTreeDataBuilder fromDataSource(String fromDataSource){
        DynamicTreeDataBuilder data = new DynamicTreeDataBuilder();
        data.fromDataSource = fromDataSource;
        return data;
    }

    /**
     * keyName对应列表中的主键
     */
    private String keyName = "key";

    /**
     * valueName对应列表中提交请求是填的值
     */
    private String valueName = "value";

    /**
     * titleName对应显示的名字
     */
    private String titleName = "";

    /**
     * 查询所得，父主键的字段
     */
    private String parentKeyName = "parentKey";


    public static final class DynamicTreeDataBuilder {
        private String fromSql;
        private IListDataPicker fromListDataPicker;
        private String fromListDataPickerClassName;
        private String fromJson;
        private String fromEnums;
        private String fromDataSource;
        private String keyName;
        private String valueName;
        private String titleName;
        private String parentKeyName;

        private DynamicTreeDataBuilder() {
        }

        public static DynamicTreeDataBuilder aDynamicTreeData() {
            return new DynamicTreeDataBuilder();
        }

        public DynamicTreeDataBuilder fromSql(String fromSql) {
            this.fromSql = fromSql;
            return this;
        }

        public DynamicTreeDataBuilder fromListDataPickerClassName(String fromListDataPickerClassName) {
            this.fromListDataPickerClassName = fromListDataPickerClassName;
            return this;
        }

        public DynamicTreeDataBuilder fromJson(String fromJson) {
            this.fromJson = fromJson;
            return this;
        }

        public DynamicTreeDataBuilder fromEnums(String fromEnums) {
            this.fromEnums = fromEnums;
            return this;
        }

        public DynamicTreeDataBuilder fromDataSource(String fromDataSource) {
            this.fromDataSource = fromDataSource;
            return this;
        }

        public DynamicTreeDataBuilder keyName(String keyName) {
            this.keyName = keyName;
            return this;
        }

        public DynamicTreeDataBuilder valueName(String valueName) {
            this.valueName = valueName;
            return this;
        }

        public DynamicTreeDataBuilder titleName(String titleName) {
            this.titleName = titleName;
            return this;
        }

        public DynamicTreeDataBuilder parentKeyName(String parentKeyName) {
            this.parentKeyName = parentKeyName;
            return this;
        }

        public DynamicTreeData build() {
            DynamicTreeData dynamicTreeData = new DynamicTreeData();
            dynamicTreeData.setFromSql(fromSql);
            dynamicTreeData.setFromListDataPicker(fromListDataPicker);
            dynamicTreeData.setFromListDataPickerClassName(fromListDataPickerClassName);
            dynamicTreeData.setFromJson(fromJson);
            dynamicTreeData.setFromEnums(fromEnums);
            dynamicTreeData.setFromDataSource(fromDataSource);
            dynamicTreeData.setKeyName(keyName);
            dynamicTreeData.setValueName(valueName);
            dynamicTreeData.setTitleName(titleName);
            dynamicTreeData.setParentKeyName(parentKeyName);
            return dynamicTreeData;
        }
    }
}
